<?php
class FullTimeAction extends AppAction
{
	private $fullTimeLib;
	private $adminGrand;
	function __construct()
	{
		parent::__construct ();
		require_once APP_LIB_PATH . 'fullTimeLib.php';
		$this->fullTimeLib = new FullTimeLib ();
		AdminVisitor::checkGrant ( 'fullTime' );
	}
	
	public function gradeedit()
	{
		ViewData::$form_data = new FullTimeGradeClass ();
		ViewData::$form_hint = new FullTimeGradeClass ();
		if (isset ( $_GET ['gradeId'] ))
		{
			ViewData::$form_data = $this->fullTimeLib->getGradeByGradeId ( $_GET ['gradeId'] );
		}
		if ($_POST)
		{
			$this->fullTimeLib->checkGradeForm ();
			if (! BaseAction::isObjectEmpty ( ViewData::$form_hint ))
			{
				BaseAction::loadView ( "admin/fullTimeGradeEdit" );
			}
			try
			{
				$this->fullTimeLib->setGradeLogic ();
				Header( "Location:  ".siteUrl('grade/fulltimegradelist')."");
			} catch ( Exception $e )
			{
				ViewData::$form_hint->Message = $e->getMessage ();
			}
		}
		BaseAction::loadView ( 'admin/fullTimeGradeEdit' );
	}
	
	public function gradedel()
	{
		ViewData::$form_data->isHaveDelGrant=FALSE;
		$adminInfo = AdminSession::getAdminSessionInfo ();
		if($adminInfo['AdminName']!='admin'){
			BaseAction::adminError ( "您没有权限操作" );
		}
		if (! isset ( $_GET ['gradeId'] ))
		{
			BaseAction::adminError ( "请不要非法访问" );
		}
		$this->fullTimeLib->delGradeByGradeId ( $_GET ['gradeId'] );
		BaseAction::adminSuccess ( "删除成功", siteUrl ( 'grade/fullTimegradeList' ) );
	}
	
	public function studentlist()
	{
		$where = "where GradeId=" . $_GET ['gradeId']." and RegistStatus >=1";
		ViewData::$form_data->studentList = $this->fullTimeLib->getStudentList ( $where );
		BaseAction::loadView ( 'admin/fullTimeStudentList' );
	}
	public function studentexportexcel()
	{
		if (isset ( $_POST ['Id'] ) && isset ( $_GET ['menu'] ))
		{
			if ($_GET ['menu'] == 'exportExcel')
			{
				$this->fullTimeLib->exportExcel ( $_POST ['Id'] );
			}
		}
		BaseAction::adminError ( "请不要非法操作" );
	}
	public function studentview()
	{
		if (! isset ( $_GET ['studentId'] ))
		{
			BaseAction::adminError ( "请不要非法访问" );
		}
		ViewData::$form_data = $this->fullTimeLib->getById ( $_GET ['studentId'] );
		ViewData::$form_hint = new RegisteFullTimeClass ();
		BaseAction::loadView ( "admin/fullTimeStudentView" );
	}
	
	public function studentedit()
	{
		if (! isset ( $_GET ['studentId'] ))
		{
			BaseAction::adminError ( "请不要非法访问" );
		}
		ViewData::$form_data = $this->fullTimeLib->getById ( $_GET ['studentId'] );
		ViewData::$form_data->GradeList = $this->fullTimeLib->getGradeList ();
		ViewData::$title = "学生信息修改";
		ViewData::$form_hint = new RegisteFullTimeClass ();
		if ($_POST)
		{
			$this->fullTimeLib->checkEditForm ();
			if (! BaseAction::isObjectEmpty ( ViewData::$form_hint ))
			{
				BaseAction::loadView ( "admin/fullTimeStudentEdit" );
			}
			try
			{
				$this->fullTimeLib->editLogic ( $_GET ['studentId'] );
				Header ( "Location:  " . siteUrl ( 'fullTime/studentlist?gradeId=' . $_GET ['gradeId'] ) );
				BaseAction::adminSuccess ( "修改成功", siteUrl ( 'fullTime/studentedit?gradeId=' . $_GET ['gradeId'] . '&studentId=' . $_GET ['studentId'] . '' ) );
			} catch ( Exception $e )
			{
				ViewData::$form_hint->Message = $e->getMessage ();
			}
		}
		
		BaseAction::loadView ( "admin/fullTimeStudentEdit" );
	}
	
	public function studentdel()
	{
		if (! isset ( $_GET ['studentId'] ))
		{
			BaseAction::adminError ( "请不要非法访问" );
		}
		$this->fullTimeLib->delStudentByStudentId ( $_GET ['studentId'] );
		BaseAction::adminSuccess ( "删除成功", siteUrl ( 'fullTime/studentlist?gradeId=' . $_GET ['gradeId'] ) );
	}
	
	public function financelist()
	{
		if (! isset ( $_GET ['studentId'] ))
		{
			BaseAction::adminError ( "请不要非法访问" );
		}
		$studentInfo=$this->fullTimeLib->getById($_GET ['studentId']);
		ViewData::$form_data->StudentName=$studentInfo->StudentName;
		require_once APP_LIB_PATH . 'financeLib.php';
		$dailyModel = new FinanceLib ();
		ViewData::$form_data->list = $dailyModel->getDailyInfoByStudentIdAndMoneyType ( $_GET ['studentId'], 3 );
		BaseAction::loadView ( 'admin/fullTimeFinanceList');
	}
	public function financeadd()
	{
		if (! isset ( $_GET ['studentId'] ))
		{
			BaseAction::adminError ( "请不要非法访问" );
		}
		require_once APP_LIB_PATH . 'financeLib.php';
		ViewData::$form_data = new FinanceDailyClass ();
		ViewData::$form_hint = new FinanceDailyClass ();
		
		if ($_POST)
		{
			$this->fullTimeLib->FinanceAddForm ();
			if (! BaseAction::isObjectEmpty ( ViewData::$form_hint ))
			{
				BaseAction::loadView ( "admin/fullTimeFinanceAdd" );
			}
			try
			{
				$this->fullTimeLib->FinanceAddLogic ();
				BaseAction::adminSuccess ( "添加成功", siteUrl ( 'fullTime/studentlist?gradeId=' . $_GET ['gradeId'] ) );
			} catch ( Exception $e )
			{
				ViewData::$form_hint->Message = $e->getMessage ();
			}
		}
		BaseAction::loadView ( "admin/fullTimeFinanceAdd" );
	}
	public function delCheckStudent() {
		try {
			if (isset ( $_POST ['Id'] ) && isset ( $_GET ['menu'] )) {
				if ($_GET ['menu'] == 'delCheck') {
					$this->fullTimeLib->delCheckStudent ( $_POST ['Id'] );
					BaseAction::adminSuccess ( "删除成功", siteUrl ( 'fulltime/studentlist?gradeId=' . $_GET ['gradeId'] ) );
					exit ();
				}
			}
			BaseAction::adminError ( "请不要非法操作" );
		} catch ( Exception $e ) {
			BaseAction::adminError ( $e->getMessage ());
		}
	}
	
}